const BehaviorAll = require("../../../behaviors/behavior_all.js");
const ServiceOrder = require("../../../service/service_order.js");
const ServiceScore = require("../../../service/service_score.js");

Component({
  /**
   * behaviors
   */
  behaviors: [BehaviorAll],
  /**
   * 页面的初始数据
   */
  data: {
    triggerSubmitFlag: false,
    score: 0,
    amount: 0,
    allScore: 0
  },
  /**
   * 方法
   */
  methods: {
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      const _this = this;
      // 加载数据
      ServiceScore.find(function (data) {
        _this.setData({
          allScore: data
        })
      })
    },
    /**
     * 提交
     */
    car_onSubmit: function(e){
      const _this = this;
      const products = e.detail.selectedData;
      const sendData = [];
      for (let product of products){
        console.log(product)
        sendData.push({ 'id': product.id, 'amount': product.amount})
      }
      //
      ServiceOrder.createGrade(sendData, function(data){
        e.detail.callback();
        wx.navigateTo({
          url: '../pay/pay?id=' + data.id,
        })
      });
    },
    /**
     * 激活提交
     */
    onTriggerSubmit: function(e){
      this.setData({ triggerSubmitFlag: true })
    },
    /**
     * 数据改变
     */
    car_onChange: function(e){
      const _this = this;
      _this.setData({
        score: e.detail.total,
        amount : e.detail.amount
      })
    }
  }

})